<?php

namespace App\Trip\Plane\Requests;

trait TraitFromToDateRequest
{
    public function getFrom(): AirportRequest
    {
        if (is_array($this->req)) {
            $from = $this->req['from'];
        } else {
            $from = $this->req->input('from');
        }

        if ($from instanceof AirportRequest) {
            return $from;
        }

        return new AirportRequest($from);
    }

    public function getTo(): AirportRequest
    {
        if (is_array($this->req)) {
            $to = $this->req['to'];
        } else {
            $to = $this->req->input('to');
        }
        if ($to instanceof AirportRequest) {
            return $to;
        }
        return new AirportRequest($to);
    }

    public function getTripDate(): string
    {
        if (is_array($this->req)) {
            $trip_date = $this->req['trip_date'];
        } else {
            $trip_date = $this->req->input('trip_date');
        }
        return $trip_date;
    }
}